#include "Game.h"

void InitializeGame(game &g)
{
	InitializeTable(g.gameTable);
	g.currentPlayerID = 0;
	g.fini = false;
}

void DisplayGame(const game &g)
{
	//DisplayTable(g.gameTable);
}

void Play(game &g)
{
	PlayTurn(g);
	g.currentPlayerID++;
	PlayTurn(g);
	return;
}
/*Execution du jeu*/
void PlayTurn(game &g)
{
	//std::cout << "COCHONNERIE" << std::endl;
	Distribute(g.gameTable, g.gameTable.players[g.currentPlayerID]);
	//std::cout << "COCHONNERIE" << std::endl;
	Distribute(g.gameTable, g.gameTable.players[g.currentPlayerID]);
	DisplayTable(g.gameTable);
	g.gameTable.players[g.currentPlayerID].nbCardDistributed = 2;
	do
	{
		MenuHitOrStand(g);
		g.gameTable.players[g.currentPlayerID].stand = ProcessHitOrStand(g.gameTable.players[g.currentPlayerID], g.choix, g);
	} while (g.gameTable.players[g.currentPlayerID].nbCardDistributed < 5 && g.gameTable.players[g.currentPlayerID].score < 21 && g.gameTable.players[g.currentPlayerID].stand == false);
	return;
}
/*Choix du player de rajouter une carte ou d'arreter*/
void MenuHitOrStand(game &g)
{
	int choice;
	choice = ChooseHitOrStand();
	ProcessHitOrStand(g.gameTable.players[g.currentPlayerID], choice, g);
}
/*Le joueur fais son choix*/
int ChooseHitOrStand()
{
	int choice;
	std::cout << "Hit(0) or Stand(1)?"; std::cin >> choice;
	return choice;
}
/*Determine les actions apres le choix*/
bool ProcessHitOrStand(player& p, int choix, game &g)
{
	if (choix == 0){
		Distribute(g.gameTable, p);
		g.gameTable.players[g.currentPlayerID].nbCardDistributed++;
		DisplayTable(g.gameTable);
		g.fini = false;
		p.score = HandValue(p.playerHand);
		p.playerHand.handValue = 0;
		//std::cout << p.score << std::endl;
	}
	else if (choix == 1)
	{
		g.fini = true;
	}
	return g.fini;
}